package com.witdata.controller.docker;

import com.witdata.common.domain.Result;
import com.witdata.common.domain.Status;
import com.witdata.common.domain.dto.ExecuteDto;
import com.witdata.common.domain.dto.InstanceContainerDto;
import com.witdata.framework.service.docker.ExecuteService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/docker/execute")
public class ExecuteController {
    private final ExecuteService executeService;

    @PostMapping("/create")
    public Result<String> createExecute(@Validated  @RequestBody InstanceContainerDto instanceContainerDto) {
        String executeId = executeService.createExecute(instanceContainerDto);
        return Result.ok(Status.CREATESUCCESS, executeId);
    }

    @PostMapping("/start")
    public Result<String> startExecute(@RequestBody ExecuteDto executeDto) {
        executeService.startExecute(executeDto);
        return Result.ok(Status.STARTSUCCESS);
    }

    @PostMapping("/send")
    public Result<String> sendCommand(@RequestBody ExecuteDto executeDto) {
        executeService.sendCommand(executeDto);
        return Result.ok(Status.SENDCOMMANDSUCCESS);
    }


}
